package com.yanqu.road.server.cmd.activity.dunhuangshiku;

import com.yanqu.road.pb.dunhuangshiku.DunHuangShiKuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.dunhuangshiku.DunHuangShiKuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Description
 * @Author cwq
 * @Data 2021/4/20 22:08
 */
@Cmd(code = GameProtocol.S_DUN_HUANG_SHI_KU_TEAM_MEMBER_MANAGE, desc = "敦煌石窟队伍成员管理")
public class DunHuangShiKuTeamMemberManageCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        DunHuangShiKuProto.DunHuangShiKuTeamTeamMemberManageReqMsg req = DunHuangShiKuProto.DunHuangShiKuTeamTeamMemberManageReqMsg.parseFrom(packet.getBytes());
        int activityId = req.getActivityId();
        // 0表示同意 1表示拒绝 2 踢出队伍
        if(req.getStatus() == 2){
            // 组队伍后 不能踢出队伍
            ret = DunHuangShiKuMgr.canEnterActivityQuitTeamPeriod(player,activityId);
        }else {
            ret = DunHuangShiKuMgr.canEnterActivityJoinTeamPeriod(player,activityId);
        }
        if(ret != 0){
            return;
        }
        player.sendUnionActivityGroupPacket(CrossProtocol.C2_DUN_HUANG_SHI_KU_TEAM_MEMBER_MANAGE, req.toBuilder(), req.getActivityId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            DunHuangShiKuProto.DunHuangShiKuGetTeamListRespMsg.Builder builder = DunHuangShiKuProto.DunHuangShiKuGetTeamListRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_DUN_HUANG_SHI_KU_TEAM_MEMBER_MANAGE, builder);
        }
    }
}
